//
//  MYEmoticonKeyBoard.swift
//  NewMicroblog
//
//  Created by apple on 2016/11/2.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

private let MyCellIdentifier = "MyCellIdentifier"

class MYEmoticonKeyBoard: UIView {

    fileprivate lazy var toolBar: MYEmoticonToolBar = MYEmoticonToolBar()

    override init(frame: CGRect) {
        super.init(frame: frame)
        setupUI()
    }
    ///搭建主界面
    private func setupUI(){
        backgroundColor = UIColor.red
        addSubview(toolBar)
        addSubview(emotionCollectionView)
        toolBar.snp_makeConstraints { (make) in
            make.bottom.leading.trailing.equalTo(self)
            make.height.equalTo(35)
        }
        emotionCollectionView.snp_makeConstraints { (make) in
            make.top.left.right.equalTo(self)
            make.bottom.equalTo(toolBar.snp_top)
        }

    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    /// 建立视图
    fileprivate lazy var emotionCollectionView : UICollectionView = {
        let flowLayout = UICollectionViewFlowLayout()
        let view = UICollectionView(frame: CGRect.zero, collectionViewLayout: flowLayout)
         view.isPagingEnabled = true
        view.showsVerticalScrollIndicator = true
        view.showsHorizontalScrollIndicator = true
        view.bounces = false
        view.dataSource = self
        view.delegate = self
        view.register(MYEmoticonViewCell.self, forCellWithReuseIdentifier: MyCellIdentifier)
        return view
    }()

    override func layoutSubviews() {
        super.layoutSubviews()
        let flowLayout = emotionCollectionView.collectionViewLayout as! UICollectionViewFlowLayout
         flowLayout.itemSize = emotionCollectionView.size
        flowLayout.minimumLineSpacing = 0
        flowLayout.minimumInteritemSpacing = 0
        flowLayout.scrollDirection = .horizontal
    }

}

extension MYEmoticonKeyBoard: UICollectionViewDataSource,UICollectionViewDelegate{

    func numberOfSections(in collectionView: UICollectionView) -> Int {
        return 4
    }

    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return 2
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: MyCellIdentifier, for: indexPath)
        as! MYEmoticonViewCell

        return cell
    }
    
}
